//
//  RootViewController.m
//  觅影
//
//  Created by  陶虹 on 16/4/6.
//  Copyright © 2016年  陶虹. All rights reserved.
//

#import "RootViewController.h"
#import "RightTabBarController.h"
#import "BaseViewController.h"
#import "RootTableViewCell.h"
#import "RecommendViewController.h"
#import "WantViewController.h"
#import "LoginViewController.h"
#import "FilmViewController.h"
@interface RootViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIButton *headerButton;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UIButton *outButton;

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    
    self.view.frame = CGRectMake(0, 0, KWIDTH, KHEIGHT);
    
    RightTabBarController *rightVc = [[RightTabBarController alloc] init];
    self.delegate = (id)rightVc;
    [self.view addSubview:rightVc.view];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 68;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerNib:[UINib nibWithNibName:@"RootTableViewCell" bundle:nil] forCellReuseIdentifier:@"rootCell"];
    NSString *name = [[NSUserDefaults standardUserDefaults]objectForKey:@"username"];
    self.nameLabel.text = name;
    self.headerButton.layer.cornerRadius = 50;
    
}

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    RootTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"rootCell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    if (indexPath.row == 0) {
        cell.titleLabel.text = @"推荐";
        cell.picView.image = [UIImage imageNamed:@"recommend"];
    }
    if (indexPath.row == 1) {
        cell.titleLabel.text = @"电影";
        cell.picView.image = [UIImage imageNamed:@"film"];
    }
    if (indexPath.row == 2) {
        cell.titleLabel.text = @"想看";
        cell.picView.image = [UIImage imageNamed:@"want"];
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        RecommendViewController *recommendVc = [[RecommendViewController alloc] initWithNibName:@"RecommendViewController" bundle:nil];
        [self.delegate pushToVc:recommendVc];
    }
    if (indexPath.row == 1) {
        FilmViewController *filmVC = [[FilmViewController alloc]initWithNibName:@"FilmViewController" bundle:nil];
        [self.delegate pushToVc:filmVC];
    }
    if (indexPath.row == 2) {
        WantViewController *wantVC = [[WantViewController alloc]initWithNibName:@"WantViewController" bundle:nil];
        [self.delegate pushToVc:wantVC];
    }
    
}

#pragma mark --- 退出登录 ---
- (IBAction)outAction:(id)sender
{
    LoginViewController *longinVC = [[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil];
    [[NSUserDefaults standardUserDefaults]setBool:NO forKey:@"isLogin"];
    [[NSUserDefaults standardUserDefaults]setObject:nil forKey:@"username"];
    [[NSUserDefaults standardUserDefaults]setObject:nil forKey:@"psw"];
    
    [self presentViewController:longinVC animated:YES completion:nil];
}










- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
